package cn.group.controller;

import cn.group.service.CommentService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import utils.BaseController;

import java.util.Map;

@Api(tags = "用户评论")
@RestController
@RequestMapping(value = "/comment", produces = "text/html;charset=UTF-8")
public class CommentController extends BaseController {
    @Autowired
    private CommentService commentService;

    @ApiOperation("查询所有评论信息")
    @GetMapping("/findComments.do")
    public String findComments(Integer currentPage, Integer pageSize) {
        System.out.println(currentPage);
        System.out.println(pageSize);
        PageInfo commentsPageInfo = commentService.findComments(currentPage, pageSize);
        return writerSuccessResult(commentsPageInfo);
    }

    @ApiOperation("查询评论信息模糊查询")
    @PostMapping("/findCommentsWithLike.do")
    public String findCommentsWithLike(@RequestBody Map<String, String> paramsMap) {
        System.out.println(paramsMap);
        PageInfo commentsPageInfo = commentService.findCommentsWithLike(paramsMap);
        return writerSuccessResult(commentsPageInfo);
    }

    @ApiOperation("按日期查询评论信息")
    @PostMapping("/findCommentsWithDate.do")
    public String findCommentsWithDate(@RequestBody Map<String, String> paramsMap) {
        System.out.println(paramsMap);
        PageInfo commentsPageInfo = commentService.findCommentsWithDate(paramsMap);
        return writerSuccessResult(commentsPageInfo);
    }

    @ApiOperation("删除单条评论")
    @GetMapping("/deleteCommentById.do")
    public String deleteCommentById(Long commentId) {
        System.out.println("commentId-------" + commentId);
        int delResult = commentService.deleteCommentById(commentId);
        return writerSuccessResult(delResult);
    }
}
